package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.core.pojo.entity.Dict;
import com.atguigu.srb.core.service.DictService;
import com.atguigu.srb.result.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 数据字典 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/api/core/dict")   // 用户/核心服务/数据字典 controller
@Api(tags = "数据字典接口")
public class ApiDictController {
    @Resource
    private DictService dictService;

    @ApiOperation("根据一级数据字典的code，查找二级数据字典的name和value")
    @GetMapping("/list/{code}")
    @Cacheable(value = "dicts:cache:",key = "#code")
    public ResponseVo listByCode(@PathVariable String code){
        List<Dict> list = dictService.listByCode(code);
        return ResponseVo.ok().addData("items",list);
    }
}


